home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / pp / pushfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  2.0 KB  |  60 lines

  1. /*
  2. \funcref{pushfile}{void pushfile (\params)}
  3.     {
  4.         {char} {*name} {file name}
  5.     }
  6.     {}
  7.     {error(), xrealloc(), xstrdup()}
  8.     {popfile()}
  9.     {pushfile.c}
  10.     {
  11.         Function {\em pushfile()} is called whenever an input file should be
  12.         processed. The first time, {\em pushfile()} is called from {\em main()}
  13.         with the name of the main input file as argument. Subsequently, {\em
  14.         pushfile()} may be called from {\em directive()} when an {\em
  15.         \#include} directive is encountered.
  16.  
  17.         The files to process are kept on a filestack. This array of {\em
  18.         FILESTACK\_} structs is indexed by the variable {\em filesp}: this
  19.         index always points to the currently processed file. The filestack is
  20.         relocatable and grows upward: hence, {\em filesp} is initially --1 and
  21.         is increased to 0 when the first input file is opened.
  22.  
  23.         The elements of the filestack contain the following fields:
  24.  
  25.         \begin{itemize}
  26.  
  27.             \item {\em char $*$n} points to the name of the input file. This is
  28.             an area of allocated memory where a duplicate of the name is
  29.             stored.
  30.  
  31.             \item {\em FILE $*$f} is the associated file pointer.
  32.  
  33.             \item {\em int l} is the number of the currently processed line.
  34.  
  35.         \end{itemize}
  36.  
  37.         When {\em pushfile()} is called, {\em filesp} is increased by 1 and the
  38.         filestack is reallocated to hold information about the input file.
  39.         Next, the fields of the new stack element are assigned using {\em
  40.         xrealloc()} and {\em fopen()}. When the input file cannot be opened for
  41.         reading, an error occurs.
  42.     }
  43. */
  44.  
  45. #include "icm-pp.h"
  46.  
  47. void pushfile (name)
  48. char *name;
  49. {
  50.     filesp++;
  51.  
  52.     filestack = xrealloc (filestack, (filesp + 1) * sizeof (FILESTACK_));
  53.     filestack [filesp].n = xstrdup (name);
  54.     if (! (filestack [filesp].f = fopen (name, "r")) )
  55.         error ("cannot open input file %s", name);
  56.     filestack [filesp].l = 1;
  57.  
  58.     fprintf (outfile, "#%s\n", name);
  59. }
  60.